import book.BookList;
import user.AdminUser;
import user.NormalUser;
import user.User;

import java.util.Scanner;

public class Main {

    /**
     * 登陆,创建用户
     * @return 用户对象
     */
    public static User login() {
        System.out.println("请输入用户名: ");
        Scanner scanner = new Scanner(System.in);
        String username = scanner.nextLine();
        System.out.println("你好,"+username);
        while (true) {
            System.out.println("请输入用户类型: 1.管理员 2.普通用户");
            int choice  = scanner.nextInt();
            if(choice == 1) {
                return new AdminUser(username);
            } else if(choice == 2) {
                return new NormalUser(username);
            } else {
                System.out.println("输入错误,请重新输入!");
            }
        }
    }

    public static void main(String[] args) {
        //创建书架
        BookList bookList = new BookList();
        //用户登陆,获取用户对象
        User user = login();
        while(true) {
            //菜单选择操作
            int choice = user.menu();
            //将操作选项和书架对象传入进行操作
            user.operate(choice,bookList);
            if(choice == 0) {
                break;
            }
        }
    }
}
